package com.niit.util;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author hanli
 * @date 2025/3/4
 * @description TODO
 */
public class MybatisUtil {

    static SqlSessionFactory sqlSessionFactory;
//
    static{
        try {
            // 读取配置文件，并返回输入流 inputStream
            InputStream inputStream = Resources.getResourceAsStream("mybatis-config.xml");
            sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }
    public static SqlSession getSqlSession(){

        return sqlSessionFactory.openSession();
    }
}